package cn.ulc.common.util;


import cn.hutool.core.date.DateUtil;
import com.abc.pay.client.ebus.AlipayRequest;
import com.abc.pay.client.ebus.UnifiedPaymentRequest;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.LinkedHashMap;

public class ABCPayHelper {


    /**
     * 农行综合支付接口
     * 主要微信公众号
     * @return
     */
    public static UnifiedPaymentRequest unifiedPaymentRequest(String orderNumber, Double orderAmount, String appId, String openId, String productName, String desc , Date createdAt) {
        UnifiedPaymentRequest unifiedPaymentRequest = new UnifiedPaymentRequest();
        unifiedPaymentRequest.dicOrder.put("PayTypeID", "JSAPI");                   //设定交易类型
        unifiedPaymentRequest.dicOrder.put("OrderDate", DateUtil.format(createdAt , "yyyy/MM/dd") );                  //设定订单日期 （必要信息 - YYYY/MM/DD）
        unifiedPaymentRequest.dicOrder.put("OrderTime", DateUtil.format(createdAt , "HH:mm:ss"));                   //设定订单时间 （必要信息 - HH:MM:SS）
        unifiedPaymentRequest.dicOrder.put("OrderTimeoutDate", DateUtil.offsetMinute(new Date() , 15));     //设定订单有效期
        unifiedPaymentRequest.dicOrder.put("CurrencyCode", "156");             //设定交易币种
        unifiedPaymentRequest.dicOrder.put("OrderNo", orderNumber);                       //设定订单编号 （必要信息）
        unifiedPaymentRequest.dicOrder.put("OrderAmount", new DecimalFormat(".##").format(orderAmount));      //设定交易金额
        unifiedPaymentRequest.dicOrder.put("AccountNo" , appId);
        unifiedPaymentRequest.dicOrder.put("OpenID" , openId);
        unifiedPaymentRequest.dicOrder.put("OrderDesc" , desc);

//        Logger.info("OrderAmount : %s" , paymentRequest.dicOrder.get("OrderAmount"));
        unifiedPaymentRequest.dicOrder.put("InstallmentMark", "0");       //分期标识
        unifiedPaymentRequest.dicOrder.put("CommodityType", "0203");           //设置商品种类

        LinkedHashMap orderitem = new LinkedHashMap();
        orderitem.put("ProductName",  productName);//商品名称
        unifiedPaymentRequest.orderitems.put(1, orderitem);

        unifiedPaymentRequest.dicRequest.put("PaymentType", "8");            //设定支付类型
        unifiedPaymentRequest.dicRequest.put("PaymentLinkType", "2");    //设定支付接入方式
        unifiedPaymentRequest.dicRequest.put("NotifyType", "1");              //设定通知方式
        unifiedPaymentRequest.dicRequest.put("ResultNotifyURL", GlobalConfig.WEIXIN_PAY_CALL_BACK);    //设定通知URL地址
        unifiedPaymentRequest.dicRequest.put("IsBreakAccount", "0");            //设定支付类型
        return unifiedPaymentRequest;
    }


    /**
     * 农行综合支付接口
     * 支付宝支付
     * 应用场景： 线下防止聚合支付码，用户使用支付宝扫一扫时，使用支付宝支付
     * @return
     */
    public static AlipayRequest alipayRequest(String orderNumber, Double orderAmount, String appId, String openId, String productName, String desc , Date createdAt) {
        AlipayRequest aliPaymentRequest = new AlipayRequest();
        aliPaymentRequest.dicOrder.put("PayTypeID", "ALI_WAP");                   //设定交易类型
        aliPaymentRequest.dicOrder.put("OrderDate", DateUtil.format(createdAt , "yyyy/MM/dd") );                  //设定订单日期 （必要信息 - YYYY/MM/DD）
        aliPaymentRequest.dicOrder.put("OrderTime", DateUtil.format(createdAt , "HH:mm:ss"));                   //设定订单时间 （必要信息 - HH:MM:SS）
        aliPaymentRequest.dicOrder.put("orderTimeoutDate", DateUtil.offsetMinute(new Date() , 15));     //设定订单有效期
        aliPaymentRequest.dicOrder.put("CurrencyCode", "156");             //设定交易币种
        aliPaymentRequest.dicOrder.put("OrderNo", orderNumber);                       //设定订单编号 （必要信息）
        aliPaymentRequest.dicOrder.put("OrderAmount", new DecimalFormat(".##").format(orderAmount));      //设定交易金额
        aliPaymentRequest.dicOrder.put("AccountNo" , appId);
        aliPaymentRequest.dicOrder.put("OpenID" , openId);
        aliPaymentRequest.dicOrder.put("OrderDesc" , desc);
        aliPaymentRequest.dicOrder.put("TimeoutExpress", DateUtil.offsetMinute(new Date() , 15));     //设定订单有效期

//        Logger.info("OrderAmount : %s" , paymentRequest.dicOrder.get("OrderAmount"));
        aliPaymentRequest.dicOrder.put("InstallmentMark", "0");       //分期标识
        aliPaymentRequest.dicOrder.put("CommodityType", "0203");           //设置商品种类

        LinkedHashMap orderitem = new LinkedHashMap();
        orderitem.put("ProductName",  productName);//商品名称
        aliPaymentRequest.orderitems.put(1, orderitem);

        aliPaymentRequest.dicRequest.put("PaymentType", "9");            //设定支付类型
        aliPaymentRequest.dicRequest.put("PaymentLinkType", "2");    //设定支付接入方式
        aliPaymentRequest.dicRequest.put("NotifyType", "1");              //设定通知方式
        aliPaymentRequest.dicRequest.put("ResultNotifyURL", GlobalConfig.Ali_PAY_CALL_BACK);    //设定通知URL地址
        aliPaymentRequest.dicRequest.put("IsBreakAccount", "0");            //设定支付类型
        return aliPaymentRequest;
    }

}
